package com.test.dao;

import java.util.Map;

import javax.sql.DataSource;

import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper;
import org.springframework.jdbc.core.simple.SimpleJdbcCall;

public class MyPageDAOBase {
	protected DataSource dataSource;
	
	public void setDataSource(DataSource dataSource){
		this.dataSource = dataSource;
	}
	
	public Map<String, Object> executeSP(String procName, 
								SqlParameterSource paramSrc){
		SimpleJdbcCall jdbcCall = new SimpleJdbcCall(
				this.dataSource).withProcedureName(procName);
		return jdbcCall.execute(paramSrc);
	}
	
	public Map<String, Object> executeSP(String procName){
    	SimpleJdbcCall jdbcCall = new SimpleJdbcCall(
    			this.dataSource).withProcedureName(procName);
    	return jdbcCall.execute();
    }
	
	public <T> Map<String, Object> executeSP(String procName,
			SqlParameterSource paramSrc, Class<T> classRow){
		SimpleJdbcCall jdbcCall = new SimpleJdbcCall(
				this.dataSource).withProcedureName(procName).
				returningResultSet("result", 
						ParameterizedBeanPropertyRowMapper.
						newInstance(classRow));
		return paramSrc != null ? jdbcCall.execute(paramSrc) : 
								jdbcCall.execute();
	}
}
